<script setup>

</script>

<template>
  <div>
    <div class="carriermanagement">
      <h2><b>基础信息</b></h2>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="承运商编码" prop="carrierID" class="carrierID">
          <el-input v-model="form.carrierID" placeholder="请输入公司名称" />
        </el-form-item>


        <el-form-item label="公司名称" prop="companyName" class="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称" />
        </el-form-item>

        <el-form-item label="承运商类型" class="carrierType">
          <el-select v-model="form.carrierType" placeholder="请选择" clearable>
            <el-option label="合同物流承运商" value="合同物流承运商"></el-option>
            <el-option label="专线物流承运商" value="专线物流承运商"></el-option>
            <el-option label="第三方物流承运商" value="第三方物流承运商"></el-option>
            <el-option label="临时供应商" value="临时供应商"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="营业执照号码" prop="businessLicenseNumber" class="businessLicenseNumber">
          <el-input v-model="form.businessLicenseNumber" placeholder="请输入营业执照号码" />
        </el-form-item>

        <el-form-item label="税务登记号码" prop="taxRegistrationNumber" class="taxRegistrationNumber">
          <el-input v-model="form.taxRegistrationNumber" placeholder="请输入税务登记号码" />
        </el-form-item>

        <el-form-item label="法人代表" prop="legalRepresentative" class="legalRepresentative">
          <el-input v-model="form.legalRepresentative" placeholder="请输入法人代表" />
        </el-form-item>

        <el-form-item label="区域" prop="region" class="region">
          <!--          <el-cascader-->
          <!--            v-model="value"-->
          <!--            :options="options"-->
          <!--            @change="handleChange" clearable></el-cascader>-->
          <el-select v-model="form.region" placeholder="请选择" clearable>
            <el-option label="四川省" value="四川省"></el-option>
            <el-option label="广东省" value="广东省"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="公司地址" prop="compantAddress" class="compantAddress">
          <el-input v-model="form.compantAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>

        <el-form-item label="邮编" prop="zipCode" class="zipCode">
          <el-input v-model="form.zipCode" placeholder="请输入邮编" />
        </el-form-item>

<!--        <el-form-item label="承运商状态" class="customerStatus">-->
<!--          <el-switch v-model="form.customerStatus"></el-switch>-->
<!--        </el-form-item>-->

        <el-form-item label="备注信息" prop="remarks" class="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>

      </el-form>
    </div>

    <div class="lian">
      <h2><b>联系人信息</b></h2>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入姓名" />
        </el-form-item>

        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>

        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门" />
        </el-form-item>

        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位" />
        </el-form-item>

        <el-form-item label="E-mail" prop="email">
          <el-input v-model="form.email" placeholder="请输入E-mail" />
        </el-form-item>

        <el-form-item label="QQ" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入QQ" />
        </el-form-item>

      </el-form>

    </div>

    <div class="cai">
      <h2><b>财务信息</b></h2>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发票抬头" prop="invoiceTitle">
          <el-input v-model="form.invoiceTitle" placeholder="请输入发票抬头" />
        </el-form-item>

        <el-form-item label="纳税人识别号" prop="taxpayerID">
          <el-input v-model="form.taxpayerID" placeholder="请输入纳税人识别号" />
        </el-form-item>

        <el-form-item label="开户行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户行" />
        </el-form-item>

        <el-form-item label="开户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入开户名称" />
        </el-form-item>

        <el-form-item label="银行账号" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账号" />
        </el-form-item>
      </el-form>
    </div>

    <div class="bao">
      <el-button type="primary" @click="submitForm">保存</el-button>
      <el-button @click="cancel()">取消</el-button>

    </div>


  </div>


</template>
<style>
.bao{
  text-align: right;
  padding: 100px;
}

.cai{
  margin-left: 50px;
}

.lian{
  margin-left: 50px;
}
.carriermanagement {
  margin-left: 50px;
}

.el-form-item {
  display: inline-block;
  margin-right: 20px; /* 调整间距 */
}

.companyName,
.businessLicenseNumber,
.taxRegistrationNumber,
.legalRepresentative,
.zipCode {
  width: 300px;
}

.companyAddress,
.remarks {
  width: 550px;
}

.carrierType,
.region,
.customerStatus {
  width: auto; /* 自适应宽度 */
}
</style>

<script>
import {addCarriermangement, getCarriermangement, updateCarriermangement} from "@/api/carriermangement/carriermangement";


export default {
  data() {
    return {

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyName: [
          { required: true, message: "公司名称不能为空", trigger: "blur" }
        ],

      }
    }
  },
  created() {
    // this.getList();
    console.log( this.$route.query.id+"....."+(this.$route.query.id!==undefined))
    if(this.$route.query.id!==undefined){
      this.findCarriermangement();
    }

  },
  methods: {

    cancel(){
      this.$router.push({ path: '/carriermanagementindex' })
    },


    findCarriermangement(){
      var id = this.$route.query.id;
      getCarriermangement(id).then(response => {
        this.form = response.data;
      });
    },

    /** 保存按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCarriermangement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              // this.open = false;
              // this.getList();
              this.$router.push({ path: '/carriermanagementindex' })
            });
          } else {
            addCarriermangement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              // this.open = false;
              // this.getList();
              this.$router.push({ path: '/carriermanagementindex' })
            });
          }
        }
      });
    },
  }

}

</script>
